import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    List<List<Integer>> ret = new ArrayList<>();
    List<Integer> path = new ArrayList<>();

    public List<List<Integer>> combinationSum2(int[] nums, int target) {
        Arrays.sort(nums);
        dfs(1, nums, 0, target);
        return ret;
    }

    private void dfs(int pos, int[] nums, int sum, int target) {
        //剪枝
        if(sum > target) return;
        if(sum == target){
            ret.add(new ArrayList<>(path));
            return;
        }
        for (int i = pos; i < nums.length; i++) {
            //跳过重复元素
            if(i > pos && nums[i] == nums[i - 1]) continue;

            path.add(nums[pos]);
            sum += nums[pos];
            dfs(i + 1, nums, sum, target);
            //恢复现场
            sum -= nums[pos];
            path.remove(path.size() - 1);
        }

    }
}